<template>
  <el-dialog
    title="错误"
    :visible.sync="localVisible"
    width="30%"
    @close="handleClose">
    <span>{{ message }}</span>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">关闭</el-button>
      <el-button type="primary" @click="handleRetry">重试</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: 'ErrorDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    message: {
      type: String,
      default: '发生错误'
    }
  },
  computed: {
    localVisible: {
      get() {
        return this.visible;
      },
      set(value) {
        this.$emit('update:visible', value);
      }
    }
  },
  methods: {
    handleClose() {
      this.$emit('update:visible', false);
    },
    handleRetry() {
      this.$emit('retry');
      this.$emit('update:visible', false);
    }
  }
}
</script>

<style scoped>
.el-dialog__body {
  color: #f56c6c;
  padding: 20px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
</style>
